*library alias;
libname tax94 'path6';

/*Pull info about dependent kids and their PIKs*/
PROC SQL;
SELECT
COUNT(var12)+COUNT(var13)+COUNT(var14)+COUNT(var15) AS Total_Dep_PVS,
COUNT(var8)+COUNT(var9)+COUNT(var10)+COUNT(var11) AS Total_Dep_PIKs,
SUM(INPUT(var16, 1.))+SUM(INPUT(var17, 1.)) AS Total_Home_Away_Exemptions,
SUM(CASE WHEN INPUT(var16, 1.)+INPUT(var17, 1.)=value3 THEN 0
         WHEN INPUT(var16, 1.)+INPUT(var17, 1.)=value4 THEN CASE WHEN var8 IS NOT NULL THEN 1 ELSE 0 END
         WHEN INPUT(var16, 1.)+INPUT(var17, 1.)=value1 THEN (CASE WHEN var8 IS NOT NULL THEN 1 ELSE 0 END
                            +CASE WHEN var9 IS NOT NULL THEN 1 ELSE 0 END)
         WHEN INPUT(var16, 1.)+INPUT(var17, 1.)=value2 THEN (CASE WHEN var8 IS NOT NULL THEN 1 ELSE 0 END
                            +CASE WHEN var9 IS NOT NULL THEN 1 ELSE 0 END 
                            +CASE WHEN var10 IS NOT NULL THEN 1 ELSE 0 END)
         WHEN INPUT(var16, 1.)+INPUT(var17, 1.)>=value5 THEN (CASE WHEN var8 IS NOT NULL THEN 1 ELSE 0 END
                            +CASE WHEN var9 IS NOT NULL THEN 1 ELSE 0 END 
                            +CASE WHEN var10 IS NOT NULL THEN 1 ELSE 0 END
                            +CASE WHEN var11 IS NOT NULL THEN 1 ELSE 0 END)
                        ELSE 0 END) AS PIKs_limited_to_children,
SUM(INPUT(var16, 1.))+SUM(INPUT(var17, 1.))+SUM(INPUT(var18, 1.))+SUM(INPUT(var19, 1.)) AS Total_Dependent_Exemptions,
SUM(CASE WHEN INPUT(var16, 1.)+INPUT(var17, 1.)+INPUT(var18, 1.)+INPUT(var19, 1.)=value3 THEN 0
         WHEN INPUT(var16, 1.)+INPUT(var17, 1.)+INPUT(var18, 1.)+INPUT(var19, 1.)=value4 THEN CASE WHEN var8 IS NOT NULL THEN 1 ELSE 0 END
         WHEN INPUT(var16, 1.)+INPUT(var17, 1.)+INPUT(var18, 1.)+INPUT(var19, 1.)=value1 THEN (CASE WHEN var8 IS NOT NULL THEN 1 ELSE 0 END
                            +CASE WHEN var9 IS NOT NULL THEN 1 ELSE 0 END)
         WHEN INPUT(var16, 1.)+INPUT(var17, 1.)+INPUT(var18, 1.)+INPUT(var19, 1.)=value2 THEN (CASE WHEN var8 IS NOT NULL THEN 1 ELSE 0 END
                            +CASE WHEN var9 IS NOT NULL THEN 1 ELSE 0 END 
                            +CASE WHEN var10 IS NOT NULL THEN 1 ELSE 0 END)
         WHEN INPUT(var16, 1.)+INPUT(var17, 1.)+INPUT(var18, 1.)+INPUT(var19, 1.)>=value5 THEN (CASE WHEN var8 IS NOT NULL THEN 1 ELSE 0 END
                            +CASE WHEN var9 IS NOT NULL THEN 1 ELSE 0 END 
                            +CASE WHEN var10 IS NOT NULL THEN 1 ELSE 0 END
                            +CASE WHEN var11 IS NOT NULL THEN 1 ELSE 0 END)
                        ELSE 0 END) AS PIKs_limited_to_exemptions
FROM tax94.file6 
;
QUIT;